翻訳と辞書
Words near each other
・ Constant folding
・ Constant Fornerod
・ Constant Fouard
・ Constant fraction discriminator
・ Constant Friendship, Maryland
・ Constant function
・ Constant Future
・ Constant Gardener Trust
・ Constant Girard
・ Constant Hawk
・ Constant Hitmaker
・ Constant Hot Water
・ Constant Hot Water (film)
・ Constant Huret
・ Constant Huysmans
Constant interface
・ Constant Janssen
・ Constant Joacim
・ Constant k filter
・ Constant Kusters
・ Constant Lambert
・ Constant Lavaux
・ Constant le Marchand de Lignery
・ Constant Lestienne
・ Constant Lievens
・ Constant linear velocity
・ Constant Madtoingué
・ Constant Marie
・ Constant Martin
・ Constant maturity


Dictionary Lists
翻訳と辞書 辞書検索 [ 開発暫定版 ]
スポンサード リンク

Constant interface : ウィキペディア英語版
Constant interface
In the Java programming language, the constant interface pattern describes the use of an interface solely to define constants, and having classes implement that interface in order to achieve convenient syntactic access to those constants.
However, since constants are very often merely an implementation detail, and the interfaces implemented by a class are part of its exported API, this practice amounts to putting implementations details into the API, which was considered inappropriate by, e.g., Java designer Joshua Bloch.〔Bloch, Joshua, Effective Java, 2nd Edition, p. 98〕 In general, collecting system constants into classes independent of behaviour might create a poor object-oriented design because it is often a sign of low cohesion. It is for these reasons that implementing constants interfaces may be considered to be an anti-pattern.
Use of this pattern has a few other downsides:
# It pollutes the class namespace with read-only variables that may not be of use.
# Contrary to the compile-time tactical utility of implementing a constants interface, the incidental run-time artifacts have little practical purpose (cf. marker interfaces which also have no methods but are useful at run-time).
# If binary code compatibility is required in future releases, the constants interface must remain forever an interface (it cannot be converted into a class), even though it has not been used as an interface in the conventional sense.
# Without an IDE that resolves where the constant are coming from, tracking it back to its containing class or interface can be time consuming.
# A variable (representing an instance) of the interface is syntactically no more useful than the interface name itself (since it has no methods).
# Unless a developer checks any implemented interfaces when adding a constant to a class, or does so but makes a typo in the new constant's name, the value of a constant can be silently changed. Consider Example 2 below.
Note that the Java libraries use constant interface pattern themselves, proving that it may be a reasonable choice in some situations.〔("SwingConstants" )〕
==Example 1==


public interface Constants
public class Calculations implements Constants


抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)
ウィキペディアで「Constant interface」の詳細全文を読む



スポンサード リンク
翻訳と辞書 : 翻訳のためのインターネットリソース

Copyright(C) kotoba.ne.jp 1997-2016. All Rights Reserved.